
#include <stdio.h>
#include "hardwareserial.h"
#include "led.h"
#include <ros.h>
#include "std_msgs/String.h"
#include "sstream"
#include <ros/time.h>
#include "timer.h"
#include "key.h"


#define DEBUG_RATE 100



Led led;	


ros::NodeHandle  nh;                                                                                      
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);                         
      
char hello[13] = "hello world!";

int main(void) 
{
	bool on_off = true;
	uint32_t previous_control_time = 0;
	SystemInit();							
	initialise();							
	led.init();  							
	KEY_Init();						
	nh.initNode();   
	nh.advertise(chatter); 
	                                                        
    while (!nh.connected())                                                       
	{
		
		led.on_off(on_off);
		on_off=!on_off;
		delay(300);
		nh.spinOnce();

	}   
	nh.loginfo("robot_Star Connected!"); 
    	
	led.on_off(true);
	led.greenLedOnOff(true);
	delay_us(10);
  																						
	                                               
	
                                                         
	while(1)
	{ 
		
		
	  
		if ((millis() - previous_control_time) >= (100000 / 2))
		{     
					
				str_msg.data=hello;		
				chatter.publish(&str_msg);
			  led.greenLedOnOff(on_off);
				on_off=!on_off;
				previous_control_time = millis();
		}	
		nh.spinOnce();		
		
	}
	return 0;

}




